package com.qf.ks.service.impl;

import com.qf.ks.constans.ResultCode;
import com.qf.ks.exception.AddDataException;
import com.qf.ks.mapper.AuthorsMapper;
import com.qf.ks.pojo.Authors;
import com.qf.ks.service.AuthorsService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AuthorsServiceImpl implements AuthorsService {

    private AuthorsMapper authorsMapper;
    @Autowired
    public void setAuthorsMapper(AuthorsMapper authorsMapper) {
        this.authorsMapper = authorsMapper;
    }

    @Override
    public void AddAuthors(Authors authors) {
        if (authors.getAuthorname()==null){
            throw new AddDataException("作者名为空", ResultCode.NULL_AUTHORS);
        }
        if (authorsMapper.selectAuthorsByName(authors.getAuthorname())!=null){
            throw new AddDataException("作者以存在",ResultCode.USERNAME_EXIST );
        }
        authorsMapper.AddAuthors(authors);
    }
}
